import logging
import unittest
import requests
from api.login import LoginApi
from parameterized import parameterized

from utils import read_file, read_file_freedom


class TestImgVerifyCode(unittest.TestCase):

    @classmethod
    def setUpClass(cls) -> None:
        cls.session = requests.session()
        cls.login_api = LoginApi(cls.session)

    # 获取图片验证码成功（随机值r为随机小数0.1515）
    @parameterized.expand(read_file_freedom("img_data", "desc,num,status"))
    def test01_img_verify_code(self, desc, num, status_code):
        # 调用接口
        response = self.login_api.get_img_verify_code(num)
        print(response.text)

        # 断言
        self.assertEqual(status_code, response.status_code)

        # 输入日志
        logging.info(f"获取图片验证码的结果为：{response}")

    # # 获取图片验证码成功（随机值r为随机整数1）
    # def test02_img_verify_code(self):
    #     # 测试数据
    #     r = 1
    #
    #     # 调用接口
    #     response = self.login_api.get_img_verify_code(r)
    #
    #     # 断言
    #     self.assertEqual(200, response.status_code)
    #
    #     # 输入日志
    #     logging.info(f"获取图片验证码的结果为：{response}")
    #
    # # 获取图片验证码失败（随机值r为空值）
    # def test03_img_verify_code(self):
    #     # 测试数据
    #     r = ""
    #
    #     # 调用接口
    #     response = self.login_api.get_img_verify_code(r)
    #
    #     # 断言
    #     self.assertEqual(404, response.status_code)
    #
    #     # 输入日志
    #     logging.info(f"获取图片验证码的结果为：{response}")
